package com.fone.player.play.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.fone.player.ApplicationManage;
import com.fone.player.R;
import com.fone.player.airone.AirOne;
import com.fone.player.airone.AirServerDevice;

/**
 * AirOne设备选择列表视图适配器
 * 
 * @author lilp
 * 
 */
public class AirOneListAdapter extends BaseAdapter {
	
	public AirOneListAdapter() {
		super();
	}

	public int getCount() {
		return AirOne.getInstance().getSize();
	}

	@Override
	public Object getItem(int position) {
		return AirOne.getInstance().getDevice(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		AirOneViewHolder holder;
		if (convertView == null) {
			convertView = LayoutInflater.from(ApplicationManage.getAplicationManageInstance()).inflate(R.layout.airone_select_item, null);
			
			holder = new AirOneViewHolder();
			holder.nameTextView = (TextView) convertView
					.findViewById(R.id.airone_name);
			holder.selectCheckBox = (CheckBox) convertView
					.findViewById(R.id.airone_select_item);
			
			convertView.setTag(holder);
		} else {
			holder = (AirOneViewHolder) convertView.getTag();
		}		
		 
		 AirServerDevice air = AirOne.getInstance().getDevice(position);

		 holder.nameTextView.setText(air.server_name);
		 holder.nameTextView.setSelected(air.checked);
		 holder.selectCheckBox.setChecked(air.checked);  
	
		return convertView;
	}

	public static class AirOneViewHolder {
		public TextView nameTextView; 			// 设备名称
		public CheckBox selectCheckBox; 		// 选择框

	}

}
